package demo1;

public class Test4 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("t1正在执行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("while循环结束");
                    break ;
                }
            }
            System.out.println("t1结束");
        });
        t1.start();
        System.out.println("5秒后设置t1的interrupt");
        Thread.sleep(5000);
        t1.interrupt();
        System.out.println("t1的interrupt=true");
        System.out.println("main结束");
    }
}
